<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS margin 属性示例</title>
</head>
<body>
  
  <h3>CSS 外边距合并</h3>
  <style>
    .box {
      border: 2px solid black;
      background-color: yellowgreen;
      margin-bottom: 20px;
    }
  
    .child1 {
      margin-top: 30px;
      margin-bottom: 10px;  /*关键点，请注释查看改变 */
    }
    </style>
    <!-- 1.相邻元素的外边距合并 -->
    <div class="box">我是div标签1</div>
    <div class="box">我是div标签2</div>
    <!-- 2.父子元素的外边距合并： -->
    <div class="box">
      <p class="child1">我是div标题子元素p2</p>
      <p class="child1">我是div标题子元素p2</p>
    </div>
</body>
</html>